using Config;
using Entity;
using MoonFramework.Scripts.Event;
using MoonFramework.Template;
using Tool;
using Tool.Name;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.AI;

namespace Map.MapObject
{
    public abstract class BaseMapObject : MonoBehaviour
    {
        protected BaseMapBlock _mapBlock; //当前所在的地图块
        protected ulong _id;

        public virtual void Init(BaseMapBlock mapBlock, ulong id)
        {
            _mapBlock = mapBlock;
            _id = id;
        }
        
        public abstract bool DoHit(Actor actor,float dir);
        public abstract void Hurt(ItemWeaponInfo weapon);
        protected abstract void Dead();

        public virtual void RemoveOnMap()
        {
            _mapBlock.RemoveMapObject(_id);
            EventCenter.Instance.Callback(EventName.RemoveMapObject, gameObject.GetComponent<Collider>(), false);
        }
        #region Editor
#if UNITY_EDITOR
        [Sirenix.OdinInspector.Button]
        public void AddNavMeshObstacle()
        {
            NavMeshObstacle obs = transform.AddComponent<NavMeshObstacle>();
            BoxCollider boxCollider = GetComponent<BoxCollider>();
            CapsuleCollider capsuleCollider = GetComponent<CapsuleCollider>();
            if (boxCollider)
            {
                obs.shape = NavMeshObstacleShape.Box;
                obs.center = boxCollider.center;
                obs.size = boxCollider.size;
                obs.carving = true;
            }
            else if (capsuleCollider)
            {
                obs.shape = NavMeshObstacleShape.Capsule;
                obs.center = capsuleCollider.center;
                obs.height = capsuleCollider.height;
                obs.radius = capsuleCollider.radius;
                obs.carving = true;
            }
        }   
#endif
        #endregion
    }
}